package com.zretc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.dao.MovieArrangeMapper;
import com.zretc.service.MovieArrangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MovieArrangeServiceImpl implements MovieArrangeService {
    @Autowired
    private MovieArrangeMapper movieArrangeMapper;
    @Override
    public PageInfo<Map<String, Object>> getAllMovieManageByAdminId(Map<String,String> params) {
        Integer pageNum = Integer.parseInt(params.get("pageNum"));
        Integer pageSize = Integer.parseInt(params.get("pageSize"));
        //调用分页插件
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String, Object>> list =  movieArrangeMapper.findAllMovieManageByAdminId(params);
        for(int i=0;i<list.size();i++){
           int showStatus = (int)list.get(i).get("showStatus");
           if (showStatus!=2){
               list.get(i).put("showStatus","正常");
           }else{
               list.get(i).put("showStatus","禁播");
           }
        }
        //将查出来的信息包装到分页插件中
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<String> getAllHallNameByAdminId(String adminId) {
        return movieArrangeMapper.findAllHallNameByAdminId(adminId);
    }

    @Override
    public int updateMovieManage(Map<String, String> params) {
        return movieArrangeMapper.setMovieManage(params);
    }

    @Override
    public int addMovieManage(Map<String, String> params) {
        return movieArrangeMapper.insertMovieManage(params);
    }
}
